<template>
  <div class='u-customerAttr'>
    <el-form-item v-for='v in attrList' :key='v.id' :label='v.name'>
      <el-select v-model='v.content' v-if='v.value_type === "0"'>
        <el-option v-for='opt in v.classes' :key='opt.id' :label='opt.name' :value='opt.id' />
      </el-select>
      <el-input v-else type='text' v-model.trim='v.content' />
    </el-form-item>
  </div>
</template>

<script>
export default {
  name: 'u-attr',

  data() {
    return {
      attrList: []
    }
  },

  mounted() {
    this.getAttributes()
  },

  methods: {
    async getAttributes() {
      const { code, data } = await this.$api.utilsGetAttributes({
        aMerchantId: this.aFirmId
      })
      if (code === 0) {
        this.formatData(data.list)
      }
    },

    formatData(data) {
      this.attrList = []
      data.forEach(v => {
        if (v.is_require === '0') return false
        // 根据 value_type 进行判断是下拉框还是输入框
        this.attrList.push({ ...v, classes: [], content: '' })
      })
      console.log(this.attrList)
    }
  }
}
</script>

<style lang='less'>
.u-customerAttr {
  width: 100%;
  display: flex;
  margin-bottom: 22px;
}
</style>
